package org.example.lostandfound.controller;

import org.example.lostandfound.model.LostItem;
import org.example.lostandfound.model.User;
import org.example.lostandfound.service.LostItemService;
import org.example.lostandfound.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    public UserService userService;

    @Autowired
    public LostItemService lostItemService;

    //管理员获取所有用户
    @GetMapping("/users")
    public List<User> getAllUsers() {
        return userService.findAllUsers();
    }

    //管理员通过id获取用户
    @GetMapping("/users/{id}")
    public User getUserById(@PathVariable Long id) {
        return userService.findUserById(id);
    }

    //管理员添加用户
    @PostMapping("/users")
    public void createUser(@RequestBody User user) {
        userService.registerUser(user);
    }

    //管理员更新用户信息
    @PutMapping("/users/{id}")
    public void updateUser(@PathVariable Long id, @RequestBody User user) {
        user.setId(id);
        userService.updateUser(user);
    }

    //管理员删除用户
    @DeleteMapping("/users/{id}")
    public void deleteUser(@PathVariable Long id) {
        userService.deleteUser(id);
    }

    //管理员获取所有丢失物
    @GetMapping("/lost-items")
    public List<LostItem> getAllLostItems() {
        return lostItemService.findAllLostItems();
    }

    //管理员通过id获取丢失物品
    @GetMapping("/lost-items/{id}")
    public LostItem getLostItemById(@PathVariable Long id) {
        return lostItemService.findLostItemById(id);
    }

    //管理员添加丢失物品
    @PostMapping("/lost-items")
    public void createLostItem(@RequestBody LostItem lostItem) {
        lostItemService.insertLostItem(lostItem);
    }

    //管理员更新丢失物品信息
    @PutMapping("/lost-items/{id}")
    public void updateLostItem(@PathVariable Long id, @RequestBody LostItem lostItem) {
        lostItem.setLostItemId(id);
        lostItemService.updateLostItem(lostItem);
    }

    //管理员删除丢失物
    @DeleteMapping("/lost-items/{id}")
    public void deleteLostItem(@PathVariable Long id) {
        lostItemService.deleteLostItem(id);
    }


}
